package com.funny.test.components;

import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.util.Assert;

/**
 * @author fanxiao  2022/3/25
 * @since 1.0.0
 */
@Slf4j
public class AppStarter {

	@Test
	public void frozenConfiguration() {

		AnnotationConfigApplicationContext applicationContext =
				new AnnotationConfigApplicationContext();


		applicationContext.registerBean("fooBeanFactoryPostProcessor",
				FooBeanFactoryPostProcessor.class,
				FooBeanFactoryPostProcessor::new);


		applicationContext.registerBeanDefinition("foo", BeanDefinitionBuilder.
				genericBeanDefinition(Foo.class).
				addPropertyValue("memberVar", "Hello").
				getBeanDefinition());


		applicationContext.refresh();

		applicationContext.getBeanFactory().freezeConfiguration();


		Foo foo = applicationContext.getBean(Foo.class);
		log.info(foo.getMemberVar());


	}

}